package b3.widget.guide
{
	import b3.net.*;
	import b3.scene.build.*;
	import b3.scene.build.phyObj.*;
	import b3.scene.home.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.widget.home.bottom.*;
	import b3.widget.tab.Tab;
	
	import flash.display.*;
	import flash.events.*;

	public class BlueBuildingGuide extends BuildingGuide
	{
		public function BlueBuildingGuide()
		{
			super();
		}
		
		override public function step1():void
		{
			//点建筑
			var clickableHole:ClickableHole = new ClickableHole(-235, -85, 80, 80);
			clickableHole.anchor = BasicWidget.ANCHOR_MIDDLE_BOTTOM;
			addChild(clickableHole);
			//箭头
			var NewHelperArrow:Class = ResourceHelper.getInstance().getClassByName("NewHelperArrow");
			var arrow:BasicWidget = new BasicWidget();
			arrow.addChild(new NewHelperArrow());
			arrow.anchor = BasicWidget.ANCHOR_MIDDLE_BOTTOM;
			arrow.x = -200;
			arrow.y = -150;
			addChild(arrow);
			var buildingTitle:Sprite = BottomPane.getInstance().tabTitles[1];
			buildingTitle.addEventListener(MouseEvent.CLICK, onStep2);
		}
		
		private function onStep2(event:Event):void
		{
			//去除钩子
			var buildingTitle:Sprite = BottomPane.getInstance().tabTitles[1];
			buildingTitle.removeEventListener(MouseEvent.CLICK, onStep2);
			//清除所有
			clearAll();
			//点蓝楼			
			var clickableHole:ClickableHole = new ClickableHole(-265, -125, 88, 108);
			clickableHole.anchor = BasicWidget.ANCHOR_MIDDLE_BOTTOM;
			addChild(clickableHole);
			//箭头
			var NewHelperArrow:Class = ResourceHelper.getInstance().getClassByName("NewHelperArrow");
			var arrow:BasicWidget = new BasicWidget();
			arrow.addChild(new NewHelperArrow());
			arrow.anchor = BasicWidget.ANCHOR_MIDDLE_BOTTOM;
			arrow.x = -220;
			arrow.y = -200;
			addChild(arrow);
			//加钩下一步
			BuildScene.getInstance().eventDispatcher.addEventListener(BuildScene.GAME_START, onStep3);
		}  
		
		private function onStep3(event:Event):void
		{
			//去除钩子
			BuildScene.getInstance().eventDispatcher.removeEventListener(BuildScene.GAME_START, onStep3);
			//清除所有
			clearAll();
			//点击屏幕
			showTipDialog("请点击屏幕，放下最底层楼");
			BuildScene.getInstance().eventDispatcher.addEventListener(BuildScene.HEIGHT_INCREASE, onStep4);
			BuildScene.getInstance().eventDispatcher.addEventListener(BuildScene.LIFE_NUM_CHANGE, onStep5);
			BuildScene.getInstance().eventDispatcher.addEventListener(BuildScene.GAME_END, onStep6);
		}
		
		private function onStep4(event:Event):void
		{
			var towerBuilding:TowerBuilding = BuildScene.getInstance().towerBuilding;
			var tower:Tower = towerBuilding.tower;
			//点击屏幕
			if (event.type == BuildScene.HEIGHT_INCREASE)
			{
				var topBox:TowerBox = tower.getTop();
				if (topBox.perfectDropFlag)
				{
					showTipDialog("漂亮~完美重合！这时候会出现连击，人口会加倍增加哦。");
				}
				else
				{
					showTipDialog("继续点击屏幕，把楼层一层层搭建起来。");
				}
			}
		}
		
		private function onStep5(event:Event):void
		{
			showTipDialog("歪得太厉害了，楼层会掉哦！");
		}

		private function onStep6(event:Event):void
		{
			//清除所有
			clearAll();
			//去除钩子
			BuildScene.getInstance().eventDispatcher.removeEventListener(BuildScene.HEIGHT_INCREASE, onStep4);
			BuildScene.getInstance().eventDispatcher.removeEventListener(BuildScene.LIFE_NUM_CHANGE, onStep5);
			BuildScene.getInstance().eventDispatcher.removeEventListener(BuildScene.GAME_END, onStep6);
			//加钩下一步
			HomeScene.getInstance().eventDispatcher.addEventListener(HomeScene.MODE_SWITCH, onStep7);
		}
		
		private function onStep7(event:Event):void
		{
			//清除所有
			clearAll();
			//去除钩子
			HomeScene.getInstance().eventDispatcher.removeEventListener(HomeScene.MODE_SWITCH, onStep7);
			showTipDialog("请点击地面，摆放建造完毕的建筑。");
			//加钩下一步
			HomeScene.getInstance().eventDispatcher.addEventListener(HomeScene.MODE_SWITCH, onStep8);
		}
		
		private function onStep8(event:Event):void
		{
			//清除所有
			clearAll();
			//去除钩子
			HomeScene.getInstance().eventDispatcher.removeEventListener(HomeScene.MODE_SWITCH, onStep8);
			var npcDialog:NpcDialog = new NpcDialog("NpcSecretary1", ["我们还需要更多的楼，来满足更多的人入住。拜托你了！"]);
			WidgetManager.getInstance().popOutOneByOne(npcDialog);
			//分享按钮
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var buttonInvite:BasicButton = new BasicButton(ButtonBgr, "邀请");
			buttonInvite.addEventListener(MouseEvent.CLICK, onButtonInviteClick);
			npcDialog.talkDialog.addButton(buttonInvite);
			//结束
			close();
		}
		
		private function onButtonInviteClick(event:Event):void
		{
			ServerRequest.inviteFriend();
		}
	}
}